@include('admin.public.head')

<div class="ibox-title">
    <h5>課程添加</h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">

        <div class="form-group">
            <label class="col-sm-3 control-label">門店分類：</label>
            <div class="col-sm-9">
                <select class="form-control" name="store_id" id="store_id">
                    <option value="" >請選擇門店</option>
                    @foreach($select_store as $k=>$v)
                        <option value="{{$k}}" @if($select_id == $k) selected="selected" @endif>{{$v}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課室編號：</label>
            <div class="col-sm-9">
                <input type="text" name="numbering" class="form-control" placeholder="課室編號" value="{{$result->numbering??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課室容納人數：</label>
            <div class="col-sm-9">
                <input type="number" min="0" name="number" class="form-control" placeholder="課室容納人數" value="{{$result->number??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課室描述：</label>
            <div class="col-sm-8">
                <script id="content" name="content" type="text/plain" style="height:300px;">{!! $result->content??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課室圖片：</label>
            <div class="col-sm-9">
                <input type="file" name="image" class="form-control"  value="">
                <img src="{{$result->image??''}}" width="300" height="150">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <input type="hidden" name="id" value="{{$id??0}}">

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <button class="btn btn-primary do" type="submit">操作</button>
                <a href="/classroom" class="btn btn-primary" >返回課室列表</a>
            </div>
        </div>
    </form>
</div>

<script>
    var content_content = UE.getEditor('content');
    var class_faq = UE.getEditor('class_faq');
    var class_note = UE.getEditor('class_note');
    var class_introduction = UE.getEditor('class_introduction');


    $('.do').click(function(){
        var form = new FormData();

        var id = $('input[name="id"]').val();
        var store_id = $('#store_id option:selected').val();
        var content = content_content.getContent();
        var numbering = $('input[name="numbering"]').val();
        var number = $('input[name="number"]').val();
        var image = $('input[name="image"]')[0].files[0];

        form.append("id", id);
        form.append("store_id", store_id);
        form.append("numbering", numbering);
        form.append("number", number);
        form.append("content", content);
        form.append("image", image);

        $.ajax({
            type: 'POST',
            url: '/classroom_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });
</script>
